package com.cloud.code.quartz;

import com.cloud.code.quartz.jobs.MyJob;
import org.quartz.*;
import org.quartz.impl.StdSchedulerFactory;

public class Test {

    public static void main(String[] args) throws SchedulerException {
        //通过调度器工厂创建调度器对象
        Scheduler defaultScheduler = StdSchedulerFactory.getDefaultScheduler();
        //任务构建器创建任务实例
        JobDetail myJob = JobBuilder.newJob(MyJob.class).withIdentity("myJob").build();
        //触发器构建器创建触发器对象
        SimpleTrigger myTrigger = TriggerBuilder.newTrigger().withIdentity("myTrigger").withSchedule(SimpleScheduleBuilder.simpleSchedule().withIntervalInSeconds(5).repeatForever()).build();
        //关联任务和触发器
        defaultScheduler.scheduleJob(myJob,myTrigger);
        //启动
        defaultScheduler.start();
    }
}
